<template>
  <uni-popup ref="popup" type="bottom">
    <div class="pickerWrapper">
      <!--      <span style="font-size: 0">111</span>-->
      <div class="title" v-if="title">{{ title }}</div>
      <div class="buttonWrapper">
        <div class="buttonWrapper_cancel">取消</div>
        <div class="buttonWrapper_confirm" @tap="confirm">确定</div>
      </div>
      <picker-view class="picker-view" @change="handleChange">
        <picker-view-column>
          <div class="selectedYear"
               v-for="(item,index) in array"
               :key="index">
            {{ item.text }}
          </div>
        </picker-view-column>
      </picker-view>
    </div>
  </uni-popup>
</template>

<script>
  export default {
    name: "PopupPicker",
    props: {
      value: 0,
      array: {
        type: Array
      },
      title: ''
    },
    data() {
      return {
        index: 0,
      }
    },
    methods: {
      handleChange(data) {
        // console.log('handleChange',data.detail.value[0]);
        this.index = data.detail.value[0]
      },
      confirm() {
        this.$emit('input', this.index);
        this.$emit('confirm', this.index);
        this.$refs.popup.close();
      },
      open() {
        this.$refs.popup.open();
      }
    },
  }
</script>

<style scoped lang="scss">
  .pickerWrapper {
    background: white;
    border-top-left-radius: 16px;
    border-top-right-radius: 16px;
  }

  .picker-view {
    height: 400px;
    width: 100%;
  }

  .selectedYear {
    height: 80px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 32px;
    font-family: PingFangSC-Regular, PingFang SC;
    font-weight: 400;
    color: #333333;
  }

  .title {
    text-align: center;
    font-size: 32px;
    font-family: PingFangSC-Medium, PingFang SC;
    font-weight: 500;
    color: rgba(0, 0, 0, 0.8);
  }

  .buttonWrapper {
    display: flex;
    justify-content: space-between;
    padding-top: 24px;
    margin-left: 30px;
    margin-right: 30px;

    .buttonWrapper_cancel {
      display: inline-block;
      font-size: 36px;
      font-family: PingFangSC-Regular, PingFang SC;
      font-weight: 400;
      color: grey;
    }

    .buttonWrapper_confirm {
      display: inline-block;
      font-size: 36px;
      font-family: PingFangSC-Regular, PingFang SC;
      font-weight: 400;
      color: dodgerblue;
    }
  }
</style>